﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MikeSoft.Tool.Common;
using System.IO.Ports;

namespace MikeSoft.WinForm
{
    public partial class SerialPortForm : Form
    {
        SerialPorts _serialPorts = new SerialPorts();
        SerialPort _port = new SerialPort();
        public SerialPortForm()
        {
            InitializeComponent();
        }

        private void SerialPortForm_Load(object sender, EventArgs e)
        {
            cbbSerialPort.DataSource = _serialPorts.GetPortNames();
            cbbBaudRate.DataSource = _serialPorts.SerialPortBaudRate;

            MessageBox.Show(Common.GetAllIP());
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            bool bol = _serialPorts.SerialPortOpen(_port, cbbSerialPort.SelectedItem.ToString(), int.Parse(cbbBaudRate.SelectedItem.ToString()), 6);
            if (bol)
            {
                btnOpen.Enabled = false;
                MessageBox.Show("打开串口成功！");
            }
            else
            {
                MessageBox.Show("打开串口失败");
            }
        }

        private void btnSreialPortClose_Click(object sender, EventArgs e)
        {
            _serialPorts.SerialPortClose(_port);
            btnOpen.Enabled = true;
            MessageBox.Show("关闭串口");
        }
    }
}
